<template>
  <div>
    <h3>订单列表</h3>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row class="top">
        <el-col :span="6" class="topInput">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="searchQuery" @change="searchQuery">
            <el-button slot="append" icon="el-icon-search" @click="searchQuery"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="orderList" border style="width: 100%">
        <el-table-column type="index" label="#" width="180"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="180"> </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column label="是否付款">
          <el-tag type="danger" v-if="orderList.order_pay === '1'">未付款</el-tag>
          <el-tag type="success" v-else>已付款</el-tag>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <el-button size="mini" type="primary" icon="el-icon-edit"></el-button>
          <el-button size="mini" type="success" icon="el-icon-location-outline"></el-button>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[1, 3, 5, 10]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      orderList: [],
      total: 0
    }
  },
  created() {
    this.getDataList()
  },
  methods: {
    //   获取数据
    async getDataList() {
      const { data: res } = await this.$axios.get('/orders', {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) this.$message.error(res.meta.msg)
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    //   查询函数
    searchQuery() {
      this.getDataList()
    },
    // size-change
    handleSizeChange(val) {
      this.queryInfo.pagesize = val
      this.getDataList()
    },
    // pagenum-change
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val
      this.getDataList()
    }
  }
}
</script>

<style scoped>
.topInput {
  margin-bottom: 15px;
}
</style>
